import http from "src/framework/network/http";
import { defineEnum } from 'src/framework/helpers/defineEnum';


export const MenuType = defineEnum({
    目录: 'M' as MenuType,
    菜单: 'C' as MenuType,
    功能: 'F' as MenuType
})
export type MenuType = 'M' | 'C' | 'F'

export type Menu = {
    id: number
    parentId: number
    children: Menu[]
    component: string
    hidden: 0 | 1
    icon: string
    menuName: string
    menuType: MenuType
    meta: string
    orderNum: number
    path: string
    perms: string
    status: 0 | 1
}

export function menus() {
    return http.post<Menu[]>('/system/menu/getAll')
}

export function addMenu(params:Omit<Menu,'id'|'children'> & Partial<Pick<Menu,'parentId'>>) {
    return http.post('/system/menu/save', params)
}

export function updateMenu(params:Omit<Menu,'parentId'|'children'> ) {
    return http.post('/system/menu/update', params)
}

export function deleteMenu(params:Pick<Menu,'id'> ) {
    return http.post('/system/menu/delete', params)
}